package tw.asap.plus.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.CBPageAdapter;
import com.facebook.drawee.view.SimpleDraweeView;

import tw.asap.plus.R;
import tw.asap.plus.entity.response.ShopIndex;
import tw.asap.plus.ui.activity.WebActivity;

/**
 * Created by Yax on 15/11/1.
 */
public class NetworkImageHolderView implements CBPageAdapter.Holder<ShopIndex.BannerListEntity> {
    SimpleDraweeView imageView;

    @Override
    public View createView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.simple_fresco_view, null);
        imageView = (SimpleDraweeView) view.findViewById(R.id.imageView);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, ShopIndex.BannerListEntity data) {
        if (!TextUtils.isEmpty(data.getImg())) {
            imageView.setImageURI(Uri.parse(data.getImg()));
        }
        imageView.setOnClickListener(view -> {
            //点击事件
            Toast.makeText(view.getContext(), "点击了第" + position + "个\n" + "url:" + data.getUrl(),
                    Toast.LENGTH_SHORT).show();

            Intent intent = new Intent(context, WebActivity.class);
            intent.putExtra("webURL",data.getUrl());
            context.startActivity(intent);

        });
    }
}
